package org.fintool.functional;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

import org.fintool.beans.Scrip;
import org.fintool.beans.Tick;
import org.fintool.fileio.FileReader;
import org.fintool.parser.IParser;
import org.fintool.parser.Parserfactory;

public class FinanceUtilDay implements IFinanceUtil {

	public  FinanceUtilDay(){

	}

	public   void updateQuotes(){

	}


	public  void updateQuotes(String stock,String exchange)  throws Exception{
         IParser parser=Parserfactory.getFinanceParser();
        //ArrayList alRawData=null;


        	//Zero timestamp implies no file so create one
        	parser.writeRawFileData(stock, exchange, null);



        //Not zero implies data already present



	}

	public  Scrip getLatestQuoteList(final String stock,final String exchange) throws Exception{

		//Quote will Never Be latest as exchange might still be open(Difficult to ascertain programatically)
		//so update First

		updateQuotes(stock ,exchange);

		//Search in FS and get the latest
		Scrip scrip=getScripData(stock,exchange);

		//After getting scrip data try a memory test and write to file if per file analysis cannot be loaded into RAM
		//First file was 8 KB so range should be 8 to 80 KB hence 8*1000 Stocks = 8 MB to 80 MB



		return scrip;

	}

	public   final  Scrip getScripData(String stock,String exchange) throws Exception{
		Scrip scrip=null;
       //Use transform data to Scrip
		ArrayList alTransData=null;

		FileReader fr=new FileReader();
		alTransData=fr.getRawDataAsLines(fr.getTransFormFileDirPath(stock, exchange)+File.separator+fr.getTransformFileLastDate(stock, exchange));

		if(alTransData!=null){
			scrip=TransfromData.makeScripFromLines(alTransData, stock, exchange);
		}



		return scrip;



	}

	public static void main(String[] args) throws Exception {





	}



}
